home *** CD-ROM | disk | FTP | other *** search
- #include "samplerControls.h"
-
- ControlHandle rocketCntl, timeButtonCntl, timeCntl, dateCntl;
- DateTimeRec *theTime;
-
- extern WindowPtr samplerWindow;
-
- void SetUpWindowCntls( void )
- {
- Rect ctrlRect;
-
- SetRect(&ctrlRect, 5,15,37,47);
- rocketCntl = NewControl( samplerWindow, &ctrlRect, "\p",
- TRUE, 0, 0, 1, 1000*16 + 0, 0 );
-
- SetRect(&ctrlRect, 5,55,37,87);
- timeButtonCntl = NewControl( samplerWindow, &ctrlRect, "\p",
- TRUE, 0, 0, 1, 1000*16 + 1, 0 );
-
- theTime = (DateTimeRec *)NewPtrClear(sizeof(DateTimeRec));
- GetTime( theTime );
-
- SetRect(&ctrlRect, 15,95,180,115);
- timeCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
- 0, 0, 128, 16*1001 + kTimeVariation,
- (long)(theTime));
-
- SetRect(&ctrlRect, 15,120,180,140);
- dateCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
- 0, 0, 128, 16*1001 + kDateVariation,
- (long)(theTime));
- }
-
- long ticks, curWait;
-
- void HandleTimeCDEFClick(Point where)
- {
- short thePart, trackPart;
- ControlHandle ch;
-
- ticks = TickCount();
- curWait = 60;
- trackPart = TrackControl( timeCntl, where, TimeCDEFAction);
-
- if (trackPart)
- {
- HandleTimeCDEFPart( timeCntl, trackPart);
- }
- }
- void HandleDateCDEFClick(Point where)
- {
- short thePart, trackPart;
- ControlHandle ch;
-
- ticks = TickCount();
- curWait = 60;
- trackPart = TrackControl( dateCntl, where, DateCDEFAction);
-
- if (trackPart)
- {
- HandleDateCDEFPart( dateCntl, trackPart);
- }
- }
-
- pascal void TimeCDEFAction( ControlHandle ch, short part)
- {
- if (TickCount() >= ticks + curWait)
- {
- HandleTimeCDEFPart( ch, part);
- ticks = TickCount();
- curWait = 15;
- }
- }
- pascal void DateCDEFAction( ControlHandle ch, short part)
- {
- if (TickCount() >= ticks + curWait)
- {
- HandleDateCDEFPart( ch, part);
- ticks = TickCount();
- curWait = 15;
- }
- }
-
- void HandleTimeCDEFPart( ControlHandle ch, short part)
- {
- DateTimeRec *theTime;
- unsigned long timeNum;
-
- switch (part)
- {
- case kHourItem:
- SetCtlValue( ch, kHourItem);
- break;
- case kMinItem:
- SetCtlValue( ch, kMinItem);
- break;
- case kAMPMItem:
- SetCtlValue( ch, kAMPMItem);
- break;
- case kArrowButtonUp:
- theTime = (DateTimeRec *)GetCRefCon(ch);
- switch (GetCtlValue(ch))
- {
- case kHourItem:
- if (theTime->hour < 23)
- {
- (theTime->hour)++;
- }
- break;
- case kMinItem:
- if (theTime->minute < 59)
- {
- (theTime->minute)++;
- }
- break;
- case kAMPMItem:
- if ( (theTime->hour + 12) <= 23)
- {
- (theTime->hour) += 12;
- }
- break;
- }
- Draw1Control( ch );
- break;
- case kArrowButtonDown:
- theTime = (DateTimeRec *)GetCRefCon(ch);
- switch (GetCtlValue(ch))
- {
- case kHourItem:
- if (theTime->hour > 0)
- {
- (theTime->hour)--;
- }
- break;
- case kMinItem:
- if (theTime->minute > 0)
- {
- (theTime->minute)--;
- }
- break;
- case kAMPMItem:
- if ( (theTime->hour - 12) >= 0)
- {
- (theTime->hour) -= 12;
- }
- break;
- }
- Draw1Control( ch );
- break;
- default:
- SetCtlValue( ch, 0);
- break;
- }
- }
- void HandleDateCDEFPart( ControlHandle ch, short part)
- {
- DateTimeRec *theTime;
- unsigned long timeNum;
- switch (part)
- {
- case kMonthItem:
- SetCtlValue( ch, kMonthItem);
- break;
- case kDateItem:
- SetCtlValue( ch, kDateItem);
- break;
- case kYearItem:
- SetCtlValue( ch, kYearItem);
- break;
- case kDayOfWeekItem:
- SetCtlValue( ch, kDayOfWeekItem);
- break;
- case kArrowButtonUp:
- theTime = (DateTimeRec *)GetCRefCon(ch);
- switch (GetCtlValue(ch))
- {
- case kMonthItem:
- if (theTime->month < 12)
- {
- (theTime->month)++;
- }
- break;
- case kDateItem:
- case kDayOfWeekItem:
- (theTime->day)++;
- Date2Secs(theTime, &timeNum);
- Secs2Date(timeNum, theTime);
- break;
- case kYearItem:
- if (theTime->year < 2040)
- {
- (theTime->year)++;
- }
- break;
- }
- Draw1Control( ch );
- break;
- case kArrowButtonDown:
- theTime = (DateTimeRec *)GetCRefCon(ch);
- switch (GetCtlValue(ch))
- {
- case kMonthItem:
- if (theTime->month > 1)
- {
- (theTime->month)--;
- }
- break;
- case kDateItem:
- case kDayOfWeekItem:
- (theTime->day)--;
- Date2Secs(theTime, &timeNum);
- Secs2Date(timeNum, theTime);
- break;
- case kYearItem:
- if (theTime->year > 1904)
- {
- (theTime->year)--;
- }
- break;
- }
- Draw1Control( ch );
- break;
- default:
- SetCtlValue( ch, 0);
- break;
- }
- }
-